package com.lhy;
//通过继承Thread来创建线程
class ThreadDemo extends Thread{
    private Thread t;
    private String threadName;
    //类的构造
    ThreadDemo(String name){
        threadName = name;
        System.out.println("构造器： "+ threadName);
    }
    //启动线程方法
    public void run(){
        System.out.println("启动的" + threadName);
        try {
            for (int i = 0; i < 4; i++) {
                System.out.println("方法中的" + threadName+"," + i);
                Thread.sleep(3000);
            }
        } catch (InterruptedException e) {
            System.out.println("错误的异常"+ threadName + "interrupted.");
        }
        System.out.println("最终的"+threadName+"exiting.");
    }

    public void start(){
        System.out.println("结束"+threadName);
        if (t == null){
            t = new Thread(this,threadName);
            t.start();
        }
    }
}

public class Test68 {
    public static void main(String[] args) {
        ThreadDemo t1 = new ThreadDemo("线程一");
        t1.start();

        ThreadDemo t2 = new ThreadDemo("线程二");
        t2.start();
    }
}
